import java.util.Scanner;

public class 图书管理系统 {
	static Scanner s = new Scanner(System.in);
	//存放用户信息
	static String[][] user = new String[5][4];
	//存放书籍信息
	static String[][] book = new String[5][5];
	//存放出版社信息
	static String[][] pub = new String[5][3];
	
	public static void main(String[] args) {
		
		init();  //初始化
		
		login(); //登录功能
	}
	
		
		
	//用户登录页面
	
	public static void login(){
		System.out.println("1. 图书馆管理 \t2.出版社管理 \t3.退出系统");
		System.out.println("请输入如上数字选择功能：");
		int a=s.nexInt();
		switch(a){
		case 1:
			BooksManagement();
			break;
		case 2:
			pubManagement();
			break;
		case 3:
			System.exit(0);//退出系统，，调用exit方法0是参数
			break;
		default:
			System.out.println("选择错误请重新输入");
			break;
		}

	}


	//图书管理页面
	public static void BooksManagement() {
		boolean y = true;
		while(y) {
			System.out.println("1.增加	2.删除	3.更新	4.查询	5.返回上一级菜单");
			System.out.println("请输入如上数字选择功能：");
			int a = s.nextInt();
			switch(x) {
				case 1:
					AddBook();		//增加
					break;
				case 2:
					DelBook();		//删除
					break;
				case 3:
					UpdateBook();	//修改
					break;
				case 4: 
					SelectBook();	//查询
					break;
				case 5:
					y = false;		//返回上一级
					break;
				default:
					System.out.println("选择错误请重新选择");
			}
		}
	}
		//增加
		private static void AddBook() {
			System.out.println("请输入图书的ISBN编码");
			String isbn = s.next();
			System.out.println("请输入图书的书名");
			String name = s.next();
			System.out.println("请输入图书的价格");
			String price = s.next();
			System.out.println("请输入图书的出版社");
			String pub = s.next();
			System.out.println("请输入图书的作者");
			String author = s.next();
			
			int index = getIndexByIsbn(isbn);
			if(index==-1) {
				int local = getIndexFirstNull();
				if(local!=-1) {
					save(isbn,name,price,pub,author,local);
					System.out.println("新增成功");
					searchAllBook();
				}
				else {
					System.out.println("书籍槽已满，没有位置插入");
				}
			}
			else {
				System.out.println("该图书已存在不能重复添加");
			}
		}
		private static void save(String isbn,String name,String price,String pub,String author,int local) {
			book[local][0] = isbn;
			book[local][1] = name;
			book[local][2] = price;
			book[local][3] = pub;
			book[local][4] = author;
		}
		private static int getIndexFirstNull() {
			int index = -1;
			for(int i =0;i<book.length;i++) {
				if(book[i][0] == null) {
					index = i;
					break;
				}
			}
			return index;
		}
		private static int getIndexByIsbn(String isbn) {
			int index = -1;
			for(int i =0;i<book.length;i++) {
				if(isbn.equals(book[i][0])) {
					index = i;
				}
			}
			return index;
		}
		private static void searchAllBook() {
			System.out.println("    编码            书名            价格             出版社            作者");
			for(int i=0;i<book.length;i++) {
				if(book[i][0] != null) {
					for (int j=0;j<book.length;j++) {
						System.out.println(  book[i][j]		);
					}
					System.out.println();
				}
			}
		}
		//删除
		private static void DelBook() {
			searchAllBook();
			System.out.println("请输入要删除的书籍的isbn编码：");
			String isbn = s.next();
			int index = getIndexByIsbn(isbn);
			if(index != -1) {
				for (int i = index; i < book.length-1; i++) {
					book[i] =book[i+1];
					if(book[i+1] == null ) {
						break;
					}
				}
				if( book[book.length-1][0] != null) {
					book[book.length-1][0] = null;
					book[book.length-1][1] = null;
					book[book.length-1][2] = null;
					book[book.length-1][3] = null;
					book[book.length-1][4] = null;
				}
				
				System.out.println("删除成功");
				searchAllBook();
			
			}
			else {
				System.out.println("没找到要删除的书籍 信息");
			}
		}
		//修改
		private static void UpdateBook() {
			searchAllBook();
			System.out.println("请输入要更新的书籍的isbn编码：");
			String isbn = s.next();
			int index = getIndexByIsbn(isbn);
			if(index != -1) {
				System.out.println("请输入更新的书名:");
				book[index][1] = scanner.next();
				System.out.println("请输入更新的价格:");
				book[index][2] = scanner.next();
				System.out.println("请输入更新的出版社:");
				book[index][3] = scanner.next();
				System.out.println("请输入更新的作者:");
				book[index][4] = scanner.next();
				searchAllBook();
				
			}else {
				System.out.println("更新失败，没有要更新的isbn编码的书籍");
			}
		}
		//查询
		private static void SelectBook() {
			System.out.println("请输入要查询的isbn");
			String isbn = s.next();
			int index = getIndexByIsbn(isbn);
			System.out.println("编码\t 书名 \t 价格\t 出版社 \t 作者");
			printIndexBook(index);
			System.out.println();
		}
		
		private static void printIndexBook(int index) {
			for(int i =0 ; i < book[index].length; i++) {
				System.out.print(book[index][i]+"\t");
			}
			System.out.println();
		}

		
		
		
		
		
		
		
		
		
	//出版社管理
	private static void pubManagement() {
		boolean a=false;
	System.out.println("请输入要增加的出版社名称：");
	String pubName=s.next();
	System.out.println("请输入要增加的出版社地址：");
	String pubAddress=s.next();
	System.out.println("请输入要增加的出版社联系人：");
	String pubAuthor=s.next();
		int b=locat();
		if (b!=-1) {
			a=publisheradd(b,pubName,pubAddress,pubAuthor);
		}
	if (a=true) 
	{
		System.out.println("添加成功");
	}
	else {
		System.out.println("添加失败");
	}
	for (int i = 0; i < 3; i++) {
		System.out.println(publisher[i][0]);
		
	}

	private static boolean publisheradd(int b, String pubName, String pubAddress, String pubAuthor) {
	boolean a=false;
	pub[b][0]=pubName;
	pub[b][1]=pubAddress;
	pub[b][2]=pubAuthor;
	a=true;
	return a;

	}
	
	private static void init() {
			//////////用户
			user[0][0] = "馆长";			//职位
			user[0][1] = "zhangsan";	//账号
			user[0][2] = "123";			//密码
			user[0][3] = "张三";			//姓名
		
			user[1][0] = "管理员";			//职位
			user[1][1] = "lisi";		//账号
			user[1][2] = "213";			//密码
			user[1][3] = "李四";			//姓名
		
			user[2][0] = "管理员";			//职位
			user[2][1] = "wangwu";		//账号
			user[2][2] = "321";			//密码
			user[2][3] = "王五";			//姓名
			
			//////////书籍
			book[0][0] = "001";				//ISBN编码
			book[0][1] = "JAVA从入门到精通";		//书名
			book[0][2] = "59";				//价格
			book[0][3] = "清华大学出版社";		//出版社
			book[0][4] = "吴七";				//作者
			
			book[1][0] = "002";				//ISBN编码
			book[1][1] = "HTML5";			//书名
			book[1][2] = "69";				//价格
			book[1][3] = "北京大学出版社";		//出版社
			book[1][4] = "钱九";				//作者
			
			book[2][0] = "003";				//ISBN编码
			book[2][1] = "C语言";				//书名
			book[2][2] = "79";				//价格
			book[2][3] = "武汉大学出版社";		//出版社
			book[2][4] = "赵六";				//作者
			
			book[3][0] = "004";				//ISBN编码
			book[3][1] = "C++";				//书名
			book[3][2] = "89";				//价格
			book[3][3] = "武汉大学出版社";		//出版社
			book[3][4] = "赵六";				//作者
			
			book[4][0] = "005";				//ISBN编码
			book[4][1] = "C#";				//书名
			book[4][2] = "99";				//价格
			book[4][3] = "武汉大学出版社";		//出版社
			book[4][4] = "赵六";				//作者
			
			//////////出版社
			pub[0][0] = "清华大学出版社";		//出版社名
			pub[0][1] = "北京市";			//地址
			pub[0][2] = "吴七";			//联系人
			
			pub[0][0] = "北京大学出版社";		//出版社名
			pub[0][1] = "北京市";			//地址
			pub[0][2] = "钱九";			//联系人
			
			pub[0][0] = "武汉大学出版社";		//出版社名
			pub[0][1] = "武汉市";			//地址
			pub[0][2] = "赵六";			//联系人
		}
	
	
	
	
	
}